﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace baseClass.controls
{
    public partial class emWork : common.control.baseUserControl
    {
        private Color saveNormalFC = common.settings.sysColorNormalFG;
        public emWork()
        {
            InitializeComponent();
            saveNormalFC = emTypeCb.ForeColor;
            managerNameEd.BackColor = common.settings.sysColorDisableBG;
            managerCodeEd.BackColor = common.settings.sysColorDisableBG;
            SetMaxLength();
        }
        private void SetMaxLength()
        {
            data.baseDS.employeeDataTable tbl = new data.baseDS.employeeDataTable();
            recruitNoteEd.maxlen = tbl.recruitNotesColumn.MaxLength;
        }
        public virtual void Init()
        {
            emTypeCb.LoadData();
            recruitSourceCb.LoadData();
            emDepartmentCb.LoadData();
        }
        public virtual void SetData(data.baseDS.employeeRow row)
        {
            emTypeCb.myValue = (row.IsemTypeNull()?null:row.emType);
            joinDateEd.myDateTime = (row.IsjoinDateNull() ? common.Consts.constNullDate : row.joinDate);
            quitDateEd.myDateTime = (row.IsquitDateNull() ? common.Consts.constNullDate : row.quitDate);

            probationFrDateEd.myDateTime = (row.IstrialDateFrNull() ? common.Consts.constNullDate : row.trialDateFr);
            probationToDateEd.myDateTime = (row.IstrialDateToNull() ? common.Consts.constNullDate : row.trialDateTo);

            recruitSourceCb.myValue = (row.IsrecruitSourceNull() ? null : row.recruitSource);
            recruitNoteEd.Text = (row.IsrecruitNotesNull() ? null : row.recruitNotes.Trim());

            emDepartmentCb.myValue = (row.IsworkDeptNull() ? null : row.workDept);

            managerCodeEd.Text = ""; managerNameEd.Text = "";
            if (!row.IsmanagerCodeNull())
            {
                data.baseDS.employeeRow employeeRow = application.dataLibs.GetEmloyee(row.managerCode);
                if (employeeRow != null)
                {
                    managerCodeEd.Text = employeeRow.emCode;
                    managerNameEd.Text = employeeRow.fullName.Trim() + "(" + employeeRow.emCode.Trim() + ")";
                }
            }
        }
        public virtual void GetData(data.baseDS.employeeRow row)
        {
            if (emTypeCb.myValue.Trim() == "") row.SetemTypeNull(); else row.emType = emTypeCb.myValue.Trim();
            if (joinDateEd.myDateTime == common.Consts.constNullDate) row.SetjoinDateNull(); else row.quitDate = joinDateEd.myDateTime;
            if (quitDateEd.myDateTime == common.Consts.constNullDate) row.SetquitDateNull(); else row.quitDate = quitDateEd.myDateTime;
            if (probationFrDateEd.myDateTime == common.Consts.constNullDate) row.SettrialDateFrNull(); else row.quitDate = probationFrDateEd.myDateTime;
            if (probationToDateEd.myDateTime == common.Consts.constNullDate) row.SettrialDateToNull(); else row.quitDate = probationToDateEd.myDateTime;

            if (recruitSourceCb.myValue.Trim() == "") row.SetrecruitSourceNull(); else row.recruitSource = recruitSourceCb.myValue.Trim();
            if (recruitNoteEd.Text.Trim() == "") row.SetrecruitNotesNull(); else row.recruitNotes = recruitNoteEd.Text.Trim();

            if (emDepartmentCb.myValue.Trim() == "") row.SetworkDeptNull(); else row.workDept = emDepartmentCb.myValue.Trim();
            if (managerCodeEd.Text.Trim() == "") row.SetmanagerCodeNull(); else row.managerCode = managerCodeEd.Text.Trim();

        }
        public virtual bool CheckData() 
        {
            bool retVal = true;
            managerCodeLbl.ForeColor = saveNormalFC;
            if (emDepartmentCb.myValue.Trim() != "")
            {
                if (managerCodeEd.Text.Trim()=="")
                {
                    managerCodeLbl.ForeColor = common.settings.sysColorHiLightFG;
                    retVal = false;
                }
            }
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            emTypeCb.Enabled = !state;
            joinDateEd.ReadOnly = state;
            quitDateEd.ReadOnly = state;
            probationFrDateEd.ReadOnly = state;
            probationToDateEd.ReadOnly = state;

            recruitSourceCb.Enabled = !state;
            recruitNoteEd.ReadOnly = state;

            emDepartmentCb.Enabled = !state;
            managerCodeEd.ReadOnly = state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            emTypeCb.Focus();
        }
    }
}
